package com.wyp168.leetcode;

/**
 * @ClassName MinOperationsSolution
 * @Title TODO
 * @Description TODO
 * @Author wyp168
 * @Date 2022/11/29 23:14
 */
public class MinOperationsSolution {
    public static void main(String[] args) {
//        char a = '0';
//        System.out.println(a - 0);
        String s = "0100";

        MinOperationsSolution solution = new MinOperationsSolution();
        System.out.println(solution.minOperations(s));
    }

    public int minOperations(String s) {
        int count = 0;
        int flag = 0;
        for(int i = 0; i < s.length(); i ++) {
            char item = s.charAt(i);
            if (flag != item - 48) {
                count ++;
            }
            flag = Math.abs(flag - 1);
        }

        return Math.min(count, s.length() - count);
    }
}
